package com.wg.db.convert;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.StrUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 少爷123
 */
public class DoubleListConvert implements IConvert<List<Double>> {
    @Override
    public List<Double> parseObject(Object obj) {
        if (!(obj instanceof String)) {
            return new ArrayList<>();
        }

        String str = (String) obj;
        if (StrUtil.isEmpty(str)) {
            return new ArrayList<>();
        }

        String[] strings = StrUtil.splitToArray(str, ",");
        List<Double> list = new ArrayList<>(strings.length);

        for (String s : strings) {
            list.add(Convert.toDouble(s, 0.0));
        }
        return list;
    }
}
